/*
 * AdpMsg.h
 *
 *  Created on: Jan 15, 2013
 *      Author: bird
 */

#ifndef ADPMSG_H_
#define ADPMSG_H_


#include <stdio.h>
#include<string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
#include <assert.h>
#include "../minclude/HandleException.h"
namespace Msg {
#define MegLen 9
#define MaxChannel 255
/**
 *  最大支持256路
 *  message_type 为消息类型
 *   mes_text【0】 对应的频道数
 *   mes_text[1] 对应频道的命令
 *   但是用时，最好转换成 int
 */
typedef struct my_message{
	long int message_type;
	char meg_text[MegLen];
}MMessage;
/**
 * 参数前面的 i input（传入参数）
 * 			o output(传入参数)且在调用处分配处理内存
 */
class AdpMsg {
public:
	/**
	 *  len_socket means the msg type is socket  and the message length is Macro MesLen
	 *  cmd is  the command of channel( flag is channelNUM )
	 */
	static int MsgSend(const int input_cmd,const long int i_type_is_socket,const long int extend);
	/**
	 * type of the message is type_is_socket  extend_time  link to cmd id
	 * cmd id 3 , 6 speed* extend
	 * return 0 success 1 success and get nothing -1 get failed (please check log file or terminal)
	 */
	static int MsgRcv(const long int i_type_is_socket,char &o_cmdid,long int& o_extend);
	static int DeleteMsgQueue();
private:
	static int msgid; // the key is getpid
};

} /* namespace Msg */
#endif /* ADPMSG_H_ */
